<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
    <script src="//cdn.jsdelivr.net/npm/eruda"></script>
    <script>eruda.init();</script>
	<style>
	li{
		margin:10px 0;

	}
</style>
</head>
<body>
	<ol>
		<li>
			<button id="btn1" onclick="goOne()">开启蓝牙(num=5表示蓝牙已开启成功，其他未开启)</button>
		</li>
		<li>
			<button onclick="goTwo()">关闭蓝牙模块(num=1成功,0失败),调用该方法将断开所有已建立的链接并释放系统资源</button>
		</li>
		<li>
			<button onclick="goThree()">获取本机蓝牙适配器状态(num=5表示蓝牙已开启，其他未开启)</button>
		</li>
		<li>
			<button onclick="goFour()">监听蓝牙适配器状态变化事件</button>
		</li>
		<li>
			<button onclick="goFive()">开始扫描周边设备</button>
		</li>
		<li>
			<button onclick="goSix()">关闭扫描周边设备</button>
		</li>
		<li>
			<button onclick="goSeven()">获取所有已发现的蓝牙设备</button>
		</li>
		<li>
			<button onclick="goEight()">根据 uuid 获取处于已连接状态的设备</button>
		</li>
		<li>
			<button onclick="goNine()">监听寻找到新设备的事件(返回的设备identifier数组)</button>
		</li>
		<li>
			<button onclick="goTen()">连接低功耗蓝牙设备</button>
		</li>
		<li>
			<button onclick="goEleven()">断开与低功耗蓝牙设备的连接</button>
		</li>
		<li>
			<button onclick="gotewlve()">获取蓝牙设备所有 service（服务)</button>
		</li>
		<li>
			<button onclick="goThirteen()">获取蓝牙设备所有 characteristic（特征值）</button>
		</li>
		<li>
			<button onclick="goFourteen()">读取低功耗蓝牙设备的特征值的二进制数据值 （需支持read）</button>
		</li>
		<li>
			<button onclick="goFifteen()">向低功耗蓝牙设备特征值中写入二进制数据 （需支持write）</button>
		</li>
		<li>
			<button onclick="goSixteen()">启用低功耗蓝牙设备特征值变化时的 notify 功能 （需支持notify）</button>
		</li>
		<li>
			<button onclick="sevenTeen()">监听低功耗蓝牙连接的错误事件，包括设备丢失，连接异常断开等等(1已断开，2正在连接，3已经连接，4正在断开)</button>
		</li>
		<li>
			<button onclick="eightTeen()">监听低功耗蓝牙设备的特征值变化。必须先启用notify接口才能接收到设备推送的notification。</button>
		</li>
        
        <li>
            <button onclick="nineTeen()">系统信息获取</button>
        </li>
        
        <li>
            <button onclick="twenty()">数据写入</button>
        </li>
        
        <li>
            <button onclick="twentyOne()">数据读取</button>
        </li>
        
        <li>
            <button onclick="twentyTwo()">数据删除</button>
        </li>
        
        <li>
            <button onclick="twentyThree()">数据清空</button>
        </li>
        
        <li>
            <button onclick="twentyFour()">返回上一级</button>
        </li>

	</ol>
	<script src="./eruda.min.js"></script>
	<script>
		
        // eruda 调试按钮
	    var el = document.createElement('div');
	    document.body.appendChild(el);

	    eruda.init({
	        container: el,
	        tool: ['console', 'elements', 'info']
	    });
                   
		function goOne(){

            console.log(window.hilink.openBluetoothAdapter());
		}
    
        function openBluetoothAdapterCallback(resultStr) {
            console.log(resultStr);
        }
    
		function goTwo(){
            console.log(window.hilink.closeBluetoothAdapter());
		}
    
        function closeBluetoothAdapterCallback(resultStr) {
            console.log(resultStr);
        }
    
		function goThree(){
            hilink.getBluetoothAdapterState("getBluetoothAdapterStateCallback");
		}
    
        function getBluetoothAdapterStateCallback(resultStr) {
            console.log(resultStr);
        }

		function goFour(){
            
            hilink.onBluetoothAdapterStateChange("onBluetoothAdapterStateChangeCallback");
		}
    
        function onBluetoothAdapterStateChangeCallback(resultStr) {
            console.log(resultStr);
        }
    
		function goFive(){

            console.log(window.hilink.startBluetoothDevicesDiscovery([],0,0));
		}
    
		function goSix(){

			console.log(window.hilink.stopBluetoothDevicesDiscovery());
		}
    
		function goSeven(){

            hilink.getBluetoothDevices("getBluetoothDevicesCallback");
		}
    
        function getBluetoothDevicesCallback(resultStr) {
            console.log(resultStr);
        }
    
		function goEight(){

            hilink.getConnectedBluetoothDevices([],"getConnectedBluetoothDevicesCallback");
         }
    
        function getConnectedBluetoothDevicesCallback(resultStr) {
            console.log(resultStr);
        }
    
        function goNine(){
        
            hilink.onBluetoothDeviceFound("onBluetoothDeviceFoundCallback");
        }
    
        function onBluetoothDeviceFoundCallback(resultStr) {
            console.log(resultStr);
        }
    
	    function goTen(){

            console.log(window.hilink.createBLEConnection('ED14081B-52B5-544B-A211-45FAE38CE869'));
	    }

        function goEleven(){

            console.log(window.hilink.closeBLEConnection('ED14081B-52B5-544B-A211-45FAE38CE869'));
        }

	    function gotewlve(){
            
	        hilink.getBLEDeviceServices('C02D4F9A-81A6-3818-9708-C59910EEECAF',"getBLEDeviceServicesCallback");
	    }

	    function getBLEDeviceServicesCallback(resultStr) {
            console.log(resultStr);
        }

    function goThirteen(){

    	var serviceUuid = 'FFE0';

        hilink.getBLEDeviceCharacteristics('C02D4F9A-81A6-3818-9708-C59910EEECAF',serviceUuid,"getBLEDeviceCharacteristicsCallback");

    }

    function getBLEDeviceCharacteristicsCallback(resultStr) {
            console.log(resultStr);
        }

    function goFourteen(){

        var serviceUuid = '180A';
    	var characteristic = '2A23';
    	hilink.readBLECharacteristicValue('ED14081B-52B5-544B-A211-45FAE38CE869',serviceUuid,characteristic,"readBLECharacteristicValueCallback");
    }

        function readBLECharacteristicValueCallback(resultStr) {
            console.log(resultStr);
        }

    function goFifteen(){

        var serviceUuid = 'FFE0';
    	var characteristic = 'FFE1';
    	var writeStr = '01030032001e640d';
        
        var timer1=window.setInterval(function(){
                                     
                                     window.hilink.writeBLECharacteristicValue('C02D4F9A-81A6-3818-9708-C59910EEECAF',serviceUuid,characteristic,writeStr,"writeBLECharacteristicValueCallback");
                                     },1000);
    }

    function writeBLECharacteristicValueCallback(resultStr) {
        console.log(resultStr);
    }

    function goSixteen(){

        var serviceUuid = 'FFE0';
    	var characteristic = 'FFE4';
        console.log(window.hilink.notifyBLECharacteristicValueChange('ED14081B-52B5-544B-A211-45FAE38CE869',serviceUuid,characteristic,1));
        
        // notify(UUID,180A,FFE4,true)
        
       // console.log(window.hilink.notifyBLECharacteristicValueChange('ED14081B-52B5-544B-A211-45FAE38CE869','180A','FFE4',1));
    }

    function sevenTeen(){
    	window.hilink.onBLEConnectionStateChange("onBLEConnectionStateChangedCallback");
    }


    function onBLEConnectionStateChangedCallback(resultStr) {
            console.log(resultStr);
        }

    function eightTeen(){

    	window.hilink.onBLECharacteristicValueChange("onBLECharacteristicValueChangeCallback");
    }

    function onBLECharacteristicValueChangeCallback(resultStr) {
            console.log(resultStr);
        }
    
    function nineTeen(){
        
        window.hilink.getSystemInfoSync("getSystemInfoSyncCallback");
    }
    
    function getSystemInfoSyncCallback(resultStr) {
        console.log(resultStr);
    }
    
    function twenty(){
        // NjI2MjcyNzYyNjIyNzI3
        console.log(window.hilink.setStorageSync('yuKEY','12898755556277722266666y'));
    }
    
    function twentyOne(){
        
        console.log(window.hilink.getStorageSync('yuKEY'));
    }
    
    function twentyTwo() {
        
        console.log(window.hilink.removeStorageSync('yuKEY'));
    }
    
    function twentyThree() {
        
        console.log(window.hilink.clearStorageSync());
    }
    
    function twentyFour() {
        
        window.hilink.finishDeviceBleActivity();
    }
    

</script>


</body>
</html>
